﻿namespace WMS6.Web.Analytics
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.AnalyticsReportServiceRef;
    using WMS6.Web.UserControls;

    public class ShipmentOrderStatusRptList : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected Button btnSearch;
        protected HtmlForm F15421;
        protected GridView gvOrder;
        protected HtmlInputHidden hdnFrom;
        protected Label lblMsg;
        protected Label lblReceiptInquiryList;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        protected UpdatePanel up1;

        private void BindData2OrderList(ShipmentOrderStatusRptQueryEntity shipmentOrderStatusRptQuery)
        {
            this.PagerFooter.CurrentPage = int.Parse(shipmentOrderStatusRptQuery.CurrentPage);
            DataSet ds = AnalyticsReportServiceClientProxy.GetInstance().GetShipmentOrderStatusRptInfo(shipmentOrderStatusRptQuery);
            base.BindData2GridView(this.gvOrder, ds);
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            ShipmentOrderStatusRptQueryEntity shipmentOrderStatusRptQuery = this.GetShipmentOrderStatusRptQueryEntity();
            shipmentOrderStatusRptQuery.IsGetAll = true;
            string currentPageIndex = shipmentOrderStatusRptQuery.CurrentPage;
            shipmentOrderStatusRptQuery.CurrentPage = "0";
            try
            {
                using (DataSet ds = AnalyticsReportServiceClientProxy.GetInstance().GetShipmentOrderStatusRptInfo(shipmentOrderStatusRptQuery))
                {
                    base.Export2Excel("ShipmentOrderStatusRpt.xls", "15421", this.gvOrder, ds);
                }
            }
            finally
            {
                shipmentOrderStatusRptQuery.IsGetAll = false;
                shipmentOrderStatusRptQuery.CurrentPage = currentPageIndex;
                this.SetshipmentOrderStatusRptQueryEntity(shipmentOrderStatusRptQuery);
            }
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            ShipmentOrderStatusRptQueryEntity shipmentOrderStatusRptQuery = this.GetShipmentOrderStatusRptQueryEntity();
            shipmentOrderStatusRptQuery.CurrentPage = "0";
            this.BindData2OrderList(shipmentOrderStatusRptQuery);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            ShipmentOrderStatusRptQueryEntity shipmentOrderStatusRptQuery = this.GetShipmentOrderStatusRptQueryEntity();
            shipmentOrderStatusRptQuery.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2OrderList(shipmentOrderStatusRptQuery);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            ShipmentOrderStatusRptQueryEntity shipmentOrderStatusRptQuery = this.GetShipmentOrderStatusRptQueryEntity();
            shipmentOrderStatusRptQuery.ORDER_ID = "";
            shipmentOrderStatusRptQuery.EXTERN_ORDER_ID = "";
            shipmentOrderStatusRptQuery.OWNER_ID = "";
            shipmentOrderStatusRptQuery.CONSIGNEE_ID = "";
            shipmentOrderStatusRptQuery.TYPE = "";
            shipmentOrderStatusRptQuery.STATUS = "";
            shipmentOrderStatusRptQuery.StartTime = "";
            shipmentOrderStatusRptQuery.EndTime = "";
            shipmentOrderStatusRptQuery.SKU_CLASS_ID = "";
            shipmentOrderStatusRptQuery.SKU_ID = "";
            this.BindData2OrderList(shipmentOrderStatusRptQuery);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            ShipmentOrderStatusRptQueryEntity shipmentOrderStatusRptQuery = this.GetShipmentOrderStatusRptQueryEntity();
            if (int.Parse(shipmentOrderStatusRptQuery.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                shipmentOrderStatusRptQuery.CurrentPage = (int.Parse(shipmentOrderStatusRptQuery.CurrentPage) + 1).ToString();
                this.BindData2OrderList(shipmentOrderStatusRptQuery);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            ShipmentOrderStatusRptQueryEntity shipmentOrderStatusRptQuery = this.GetShipmentOrderStatusRptQueryEntity();
            if (int.Parse(shipmentOrderStatusRptQuery.CurrentPage) > 0)
            {
                shipmentOrderStatusRptQuery.CurrentPage = (int.Parse(shipmentOrderStatusRptQuery.CurrentPage) - 1).ToString();
                this.BindData2OrderList(shipmentOrderStatusRptQuery);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            ShipmentOrderStatusRptQueryEntity shipmentOrderStatusRptQuery = this.GetShipmentOrderStatusRptQueryEntity();
            this.BindData2OrderList(shipmentOrderStatusRptQuery);
        }

        private ShipmentOrderStatusRptQueryEntity GetShipmentOrderStatusRptQueryEntity()
        {
            return (base.PageQueryEntitySession as ShipmentOrderStatusRptQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                ShipmentOrderStatusRptQueryEntity shipmentOrderStatusRptQuery = this.GetShipmentOrderStatusRptQueryEntity();
                shipmentOrderStatusRptQuery.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2OrderList(shipmentOrderStatusRptQuery);
            }
        }

        protected void gvOrder_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F15421", this.gvOrder);
        }

        protected void gvOrder_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                e.Row.Attributes.Add("ondblclick", "JavaScript:document.getElementById('" + ((CheckBox) e.Row.FindControl("chbSelect")).ClientID + "').click();");
            }
        }

        protected void gvOrder_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                ShipmentOrderStatusRptQueryEntity shipmentOrderStatusRptQuery = this.GetShipmentOrderStatusRptQueryEntity();
                shipmentOrderStatusRptQuery.SortField = e.SortExpression;
                if (shipmentOrderStatusRptQuery.SortDirection == "ASC")
                {
                    shipmentOrderStatusRptQuery.SortDirection = "DESC";
                }
                else if (shipmentOrderStatusRptQuery.SortDirection == "DESC")
                {
                    shipmentOrderStatusRptQuery.SortDirection = "ASC";
                }
                this.BindData2OrderList(shipmentOrderStatusRptQuery);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            ShipmentOrderStatusRptQueryEntity shipmentOrderStatusRptQuery = new ShipmentOrderStatusRptQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    shipmentOrderStatusRptQuery.ORDER_ID = this.PreviousPage.OrderID;
                    shipmentOrderStatusRptQuery.EXTERN_ORDER_ID = this.PreviousPage.ExternOrderID;
                    shipmentOrderStatusRptQuery.OWNER_ID = this.PreviousPage.OwnerID;
                    shipmentOrderStatusRptQuery.CONSIGNEE_ID = this.PreviousPage.ConsigneeID;
                    shipmentOrderStatusRptQuery.TYPE = this.PreviousPage.Type;
                    shipmentOrderStatusRptQuery.STATUS = this.PreviousPage.Status;
                    shipmentOrderStatusRptQuery.StartTime = this.PreviousPage.StartTime;
                    shipmentOrderStatusRptQuery.EndTime = this.PreviousPage.EndTime;
                    shipmentOrderStatusRptQuery.SKU_CLASS_ID = this.PreviousPage.SkuClassID;
                    shipmentOrderStatusRptQuery.SKU_ID = this.PreviousPage.SkuID;
                }
                else
                {
                    shipmentOrderStatusRptQuery.ORDER_ID = "";
                    shipmentOrderStatusRptQuery.EXTERN_ORDER_ID = "";
                    shipmentOrderStatusRptQuery.OWNER_ID = "";
                    shipmentOrderStatusRptQuery.CONSIGNEE_ID = "";
                    shipmentOrderStatusRptQuery.TYPE = "";
                    shipmentOrderStatusRptQuery.STATUS = "";
                    shipmentOrderStatusRptQuery.StartTime = "";
                    shipmentOrderStatusRptQuery.EndTime = "";
                    shipmentOrderStatusRptQuery.SKU_CLASS_ID = "";
                    shipmentOrderStatusRptQuery.SKU_ID = "";
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            shipmentOrderStatusRptQuery.IsGetAll = false;
            shipmentOrderStatusRptQuery.CurrentPage = "0";
            shipmentOrderStatusRptQuery.PageSize = this.gvOrder.PageSize.ToString();
            shipmentOrderStatusRptQuery.SortField = "ORDER_ID";
            shipmentOrderStatusRptQuery.SortDirection = "DESC";
            this.PagerFooter.PageSize = this.gvOrder.PageSize;
            this.SetshipmentOrderStatusRptQueryEntity(shipmentOrderStatusRptQuery);
            this.BindData2OrderList(shipmentOrderStatusRptQuery);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                base.InitAnalyticsReportGridview(this.gvOrder);
                this.LoadData();
            }
        }

        private void SetshipmentOrderStatusRptQueryEntity(ShipmentOrderStatusRptQueryEntity shipmentOrderStatusRptQuery)
        {
            base.PageQueryEntitySession = shipmentOrderStatusRptQuery;
        }

        public ShipmentOrderStatusRptQuery PreviousPage
        {
            get
            {
                return (ShipmentOrderStatusRptQuery) base.PreviousPage;
            }
        }
    }
}

